<template>
	<div>
		<el-dialog :visible.sync="dialogeditUser" width="60%" :before-close="handleClose2" @opened="dialogOpened">
			<el-form ref="item" :model="item" :visible.sync="dialogeditUser">
				<el-form-item label="用户id" prop="id" :rules="[{ required: true, message: '请输入用户id' }]">
					<el-input placeholder="请输入用户id" v-model="item.id"></el-input>
				</el-form-item>
				<el-form-item label="用户名" prop="name" :rules="[{ required: true, message: '请输入用户名' }]">
					<el-input placeholder="请输入用户名" v-model="item.name"></el-input>
				</el-form-item>
				<el-form-item label="用户状态" prop="state" :rules="[{ required: true, message: '请输入用户状态' }]">
					<el-switch v-model="item.state" active-color="#13ce66" inactive-color="#ff4949"
						:active-value="true" :inactive-value="false">
					</el-switch>
				</el-form-item>
				<el-form-item label="身份证号" prop="idCard" :rules="[{ required: true, message: '请输入身份证号' }]">
					<el-input placeholder="请输入身份证号" v-model="item.idCard"></el-input>
				</el-form-item>
				<el-form-item label="手机号" prop="phone" :rules="[{ required: true, message: '请输入手机号' }]">
					<el-input placeholder="请输入手机号" v-model="item.phone"></el-input>
				</el-form-item>
				<el-form-item label="会员状态" prop="vip" :rules="[{ required: true, message: '请输入会员状态' }]">
					<el-switch v-model="item.vip" active-color="#13ce66" inactive-color="#ff4949"
						:active-value="true" :inactive-value="false">
					</el-switch>
				</el-form-item>
				<el-form-item label="账户余额" prop="userMoney" :rules="[{ required: true, message: '请输入账户余额' }]">
					<el-input placeholder="请输入账户余额" v-model="item.userMoney"></el-input>
				</el-form-item>
				<el-form-item label="头像" prop="headPhoto" :rules="[{ required: true, message: '请上传用户头像' }]">
					<el-input placeholder="请上传用户头像" v-model="item.headPhoto"></el-input>
				</el-form-item>
				<!-- <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/">
						<img v-if="imageUrl" :src="imageUrl" class="avatar">
						<i v-else class="el-icon-plus avatar-uploader-icon"></i>
					</el-upload> -->
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button>取 消</el-button>
				<el-button type="primary" @click="sure">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import axios from 'axios';
	export default {
		props: ["dialogeditUser", "row"],
		data() {
			return {
				item: {
					id: "",
					name: "",
					state: '',
					idCard: "",
					phone: "",
					vip: '',
					userMoney: "",
					headPhoto: ""
				},
			}
		},
		methods: {
			handleClose2() {
				// this.$refs.form.resetFields();
				this.$parent.dialogeditUser = false
			},
			//编辑
			sure(row) {
				// this.item = row
				axios.post("/updateUser/" + Number(this.item.id), {
					id: Number(this.item.id),
					name: this.item.name,
					headPhoto: this.item.headPhoto,
					idCard: this.item.idCard,
					phone: this.item.phone,
					state: Boolean(this.item.state),
					userMoney: Number(this.item.userMoney),
					vip: Boolean(this.item.vip),
				}).then((res) => {
					console.log(res);
					if (res.data === "用户更新成功") {
						console.log("2222")
						this.$parent.getLesson()
						this.$parent.dialogeditUser = false;
					} else {
						this.$parent.dialogeditUser = false;
					}
				});
			},
			dialogOpened(){
				this.item={...this.$props.row}
				
			}
		},
	}
	
</script>

<style>
</style>
